package com.lsy.android.motu;

import android.os.Bundle;
import android.app.ActivityGroup;
import android.content.Intent;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.ScrollView;

public class MainActivity extends ActivityGroup implements
		OnCheckedChangeListener {

	private ScrollView mContainer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
	}

	private void initView() {
		mContainer = (ScrollView) findViewById(R.id.containerBody);
		RadioButton iamge=(RadioButton) findViewById(R.id.nav_image);
		iamge.setOnCheckedChangeListener(this);
		((RadioButton) findViewById(R.id.nav_video))
				.setOnCheckedChangeListener(this);
		((RadioButton) findViewById(R.id.nav_tools))
				.setOnCheckedChangeListener(this);
		((RadioButton) findViewById(R.id.nav_download))
				.setOnCheckedChangeListener(this);
		iamge.setChecked(true);
		
	}

	private void navTo(Class<?> activity) {
		mContainer.removeAllViews();
		mContainer.addView(getLocalActivityManager().startActivity(
				activity.getSimpleName(),
				new Intent(MainActivity.this, activity))
				.getDecorView());
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			switch (buttonView.getId()) {
			case R.id.nav_image:
				navTo(ImageActivity.class);
				break;
			case R.id.nav_video:
				navTo(VideoActivity.class);
				break;
			case R.id.nav_tools:
				navTo(ToolsActivity.class);
				break;
			case R.id.nav_download:
				navTo(DownloadActivity.class);
				break;

			default:
				break;
			}
		}
	}

}
